import * as constant from "./constant"
import instance from "../../../utils/instance"

const getUserAction = (info) => {
    return {
        type: constant.GET_USER,
        info
    }
}

const getQuestionAction = (question) => {
    return {
        type: constant.GET_QUESTION,
        question
    }
}

export const getUser = (token) => {
    return (dispatch) => {
        instance.defaults.headers.common['Authorization'] = "Bearer " + token
        instance.get("/users/getUser?fields=following;followingTopic;likingAnswers;collectingQuestions")
            .then(data => {
                let user = data.data.data
                dispatch(getUserAction(user))
            })
    }
}

export const getQuestion = () => {
    return (dispatch) => {
        instance.get("/question?per_page=10&page=1").then(data => {
            let question = data.data.data
            dispatch(getQuestionAction(question))
        })
    }
}